<template>
  <div>
    <UploadExcel :on-success="handleSuccess"></UploadExcel>
  </div>
</template>

<script>
impo
export default {
  name: "",
  data() {
    return {};
  },
  created() {},
  mounted() {},
  computed: {},
  components: {},
  methods: {
    handleSuccess({ header, results }) {
      // (1)数据来源
      // header = ['手机号', '姓名', '入职日期', '转正日期', '工号']
      // results = [{"手机号":13941130879,"姓名":"高大山","入职日期":43535,"转正日期":43719,"工号":20089}]
      // (2)数据转换目标
      // arr = [{"mobile":13941130879,"username":"高大山","timeOfEntry":43535,"correctionTime":43719,"workNumber":20089}]
      const userRelations = {
        入职日期: "timeOfEntry",
        手机号: "mobile",
        姓名: "username",
        转正日期: "correctionTime",
        工号: "workNumber"
      };
        let arr = [];
        results.forEach(t => {
          let item = {};
          for (const key in t) {
            let value = t[key];
            let newKey = userRelations[key];
            item[newKey] = value;
          }
          arr.push(item);
        });
        console.log(arr);

      // 优化1,用Object.keys替换for in
      /*
      let arr = [];
      results.forEach((t) => {
        let item = {};
        Object.keys(t).forEach((key) => {
          let value = t[key];
          // console.log(key, value);
          let newKey = userRelations[key];
          item[newKey] = value;
        });
        arr.push(item);
      });
      console.log(arr);
      */

      // 优化2,用map替换forEach
    //   let arr = results.map(t => {
    //     let item = {};
    //     Object.keys(t).forEach(key => {
    //       let value = t[key];
    //       // console.log(key, value);
    //       let newKey = userRelations[key];
    //       item[newKey] = value;
    //     });
    //     return item;
    //   });
    //   console.log(arr);
    }
  }
};
</script>

<style lang="less" scoped>
</style>